﻿@model GoodsPhotoIM
@{
    ViewBag.Title = EntityNames.GoodsPhoto;
    ViewBag.PageTitle = ViewBag.Title + "_商城_内容";
}

@section Header{
    <link href="~/plugins/SigFinder/SigFinder.min.css" rel="stylesheet" />
    <link href="~/plugins/webuploader/webuploader.css" rel="stylesheet" />
}

<div class="panel panel-default">
    <header class="panel-heading">        
            <h3 class="panel-title"><span class="glyphicon glyphicon-picture"></span> 产品组图</h3>        
    </header>
    <div class="panel-body">
        <!-- gallery wrapper -->
        <div class="gallery-wrapper" id="gallery-wrapper">           
            @Html.Partial("_Photos", (IEnumerable<GoodsPhotoVM>)ViewBag.Photos)
        </div>
        <!-- end gallery wrapper -->       
    </div>
</div>

<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

@using (Ajax.BeginForm("Add", Model, new AjaxOptions()
{

    HttpMethod = "POST",
    OnBegin = "onBeginSave",
    OnComplete = "onCompleteSave",
    OnFailure = "onFailure",
    OnSuccess = "updateSuccess"
}, new { @class = "form-horizontal", role = "form" }))
{

    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    @Html.HiddenFor(model => model.GoodsId)
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title"><span class="glyphicon glyphicon-picture"></span> 上传图片</h3>
    </div>
    <div class="panel-body">
        <div class="no-gallery">


                <div class="form-group">
                    @Html.LabelFor(model => model.ImageURL, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.ImageURL, new { @class = "form-control", placeholder = Labels.ImageURL })
                            <span class="input-group-btn">
                                <button class="btn btn-default" id="btnThumbnail" type="button">浏览…</button>
                            </span>
                        </div><!-- /input-group -->
                        <span class="help-block">图片尺寸：800x800 像素</span>
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.ImageURL)
                    </div>
                </div>

                @*<div class="form-group">
                    @Html.LabelFor(model => model.Importance, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Importance, new { @class = "form-control", type = "number", placeholder = ModelMetadata.FromLambdaExpression(x => x.Importance, ViewData).Watermark })
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.Importance)
                    </div>

                </div>*@

          

        </div>
    </div>
    <div class="panel-footer text-center">
        <button type="submit" class="btn btn-primary" id="btnSave"><i class="fa fa-save fa-fw"></i>  @Buttons.Add </button>
        <a href="@Url.Action("Index","Goods")" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> @Buttons.Back</a>
    </div>
</div>
            }

@Html.Action("PopuFinder", "File")

@section Footer {

    @Scripts.Render("~/bundles/jqueryvalWithBootstrap")
<script src="/Plugins/webuploader/webuploader.min.js"></script>
<script src="/Plugins/SigFinder/FileManager.js"></script>

    <script>

        function SetThumbnail() {
            var fileUrl = $("#fileList .item.active").attr("data-file");
            $('#ImageURL').val(fileUrl);
            $('#fileManagerModal').modal('hide');
        }

    function onBeginSave() {
        $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin");
    }
    function onCompleteSave() {
        $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save");
    }
    function onFailure(data,title,message) {
        toastr.error(message, title)
    }
    function updateSuccess(data) {
        var title = '@ViewBag.Title';
        var container = $("#gallery-wrapper");
        Common.SubmitBack(data, title, container);
    }


        $(function () {
            $("#btnThumbnail").on("click", function () {
                $('#fileManagerModal').modal();
                $("#selectImage").unbind('click');
                $("#selectImage").bind("click", function () {
                    SetThumbnail();
                });
            });


            //删除数据
            $(document).on("click", ".delete-item", function (e) {
                e.preventDefault();
                var url = $(this).attr('href'), that = $(this), title = '@($"删除{ViewBag.Title}")';

                bootbox.setLocale("zh_CN");

                bootbox.confirm("是否确定删除该项？", function (result) {
                    if (result) {
                        Common.DeleteItem(url, title, that);
                    }
                });
            });

        })
    </script>
}



